#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define maxn 110
#define inf 0x3fffffff
int n, u, v, w;
int val[maxn];
int edge[maxn][maxn], vis[maxn], dis[maxn];
int MINCost = inf;
queue<int> que;
int bfs(int x)
{
    fill(vis, vis + maxn, 0);
    fill(dis, dis + maxn, inf);
    int cost = 0;
    que.push(x);
    dis[x] = 0;
    while (!que.empty())
    {
        int now = que.front();
        que.pop();
        vis[now] = 1;
        for (int i = 1; i <= n; ++i)
        {
            if (edge[now][i] == 1 && vis[i] == 0)
            {
                que.push(i);
                dis[i] = min(dis[i], dis[now] + 1);
                cost += dis[i] * val[i];
            }
        }
    }
    return cost;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> w >> u >> v;
        val[i] = w;
        edge[i][v] = edge[i][u] = edge[v][i] = edge[u][i] = 1;
    }
    for (int i = 1; i <= n; ++i)
    {
        MINCost = min(MINCost, bfs(i));
    }
    cout << MINCost;
    return 0;
}